﻿String[] str_vision = {"OFF", "ON (normal)", "ON (horizontal)"};
String[] menupoints_opt = {"Volume: (" + volume + " / 5)","Vision " + str_vision[vision],"Difficulté","Retour"};
int activeMenupoint_opt =0;
int timeBeginMenupoint_opt = millis ();
int isActiveOpt = 0;



// ---------- ----------
// code specific to the Options state
// ---------- ----------

void drawOptions ()
{
	if (isActiveOpt == 0) {
		initStateOptions();
	}
	buildOptions();
	setActiveOpt(millis () - timeBeginMenupoint_opt);
}

void initStateOptions() {
	play_multi_sound("option" + (activeMenupoint_opt+1));
	timeBeginMenupoint_opt = millis();
	isActiveOpt = 1;
}

void buildOptions() {
	for (int i = 0; i < menupoints_opt.length();i++) {
		// Set color to black
		if (activeMenupoint_opt == i) {
			fill( 255, 0, 0 );  
		} else {
			fill( 0, 0, 0 );   
		}
		strokeWeight(-1);
		rect(width/3,height/3+i*50,width/3,40);
		strokeWeight(3);
		stroke(120);
		fill ( 180 );
		textAlign(CENTER);
		PFont fontA = loadFont("arial");
        textFont(fontA, 24);

		text ( menupoints_opt[i], width/3+10, height/3+i*50+10,width/3-10,35);
	}
}

void setActiveOpt(float timeEllapsed) {
		
	if ( timeEllapsed-TIME_PER_MENUPOINT > 0) {
		activeMenupoint_opt= (activeMenupoint_opt+1) % menupoints_opt.length();
		play_multi_sound("option" + (activeMenupoint_opt+1));
		timeBeginMenupoint_opt = millis();
	}
}

void keyPressedOptions ()
{
	if( keyCode == ENTER || keyCode == 32 ) {

		if (activeMenupoint_opt == 3) {
				state = 1;
				isActive = 0;
				justCameIn = 1;
		} else if (activeMenupoint_opt == 1) {
			vision = (vision + 1) % 3;
			menupoints_opt[1] = "Vision " + str_vision[vision];
			//println("Vision set to " + str_vision[vision]);
			//println("vision_" + str_vision[vision]);
			play_multi_sound("vision_" + str_vision[vision]);
		} else if (activeMenupoint_opt == 0) {
			volume = (volume + 1) % 6;
			menupoints_opt[0] = "Volume: (" + volume + " / 5)";
			//println("Volume set to " + menupoints_opt[0]);
			play_multi_sound("option" + (activeMenupoint_opt+1));
		}
		timeBeginMenupoint_opt = millis();
		
	} else if ( keyCode == UP ) {
			activeMenupoint_opt -= 1;
			if (activeMenupoint_opt < 0) {
				activeMenupoint_opt = menupoints_opt.length()-1;
			}
			timeBeginMenupoint_opt = millis();
			play_multi_sound("option" + (activeMenupoint_opt+1));
	} else if ( keyCode == DOWN ) {
			activeMenupoint_opt += 1;
			if (activeMenupoint_opt >= menupoints_opt.length()) {
				activeMenupoint_opt = 0;
			}
			timeBeginMenupoint_opt = millis();
			play_multi_sound("option" + (activeMenupoint_opt+1));
	}
}
